package com.wh.executor;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.junit.Test;

//注意：shutdown()方法并不是终止线程的执行，而是禁止在这个Executor中添加新的任务。
public class ThreadPoolTest {

	@Test
	public void newCachedThreadPoolTest() {
		ExecutorService executorService = Executors.newCachedThreadPool();
		for(int i = 0; i < 5; i++) {
			executorService.execute(new MyThread(i));
		}
		executorService.shutdown();
	}
	
	@Test
	public void fixdThreadPoolTest() {
		ExecutorService executorService = Executors.newFixedThreadPool(2);
		for(int i = 0; i < 5; i++) {
			executorService.execute(new MyThread(i));
		}
		executorService.shutdown();
	}
	
	@Test
	public void singleThreadExecutorTest() {
		ExecutorService executorService = Executors.newSingleThreadExecutor();
		for(int i = 0; i < 5; i++) {
			executorService.execute(new MyThread(i));
		}
		executorService.shutdown();
	}
}
